package com.yb.producer.service.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description:
 * @author biaoyang
 * date 2019/4/10 001014:45
 */
@Slf4j
@Api(tags = "我的服务提供接口")
@RefreshScope
@RestController
public class ProducerServiceController {
    //用于feign-ribbon-hystrix的服务接口-------------swagger导出文档在Test的应用类里

    @Value("${producer.test}")
    private String test;

    @ApiOperation("我的hello")
    @GetMapping("/hello")
    public String hello( @ApiParam(name = "name",value = "姓名") @RequestParam String name){
        return "hello "+name+"==="+test;
    }

    @ApiOperation("我的world")
    @GetMapping("/world")
    public String world(){
        return "hello world----啊啊=-="+test;
    }

    @ApiOperation("测试网关重试接口")
    @GetMapping("/data")
    public String getData(@RequestParam("name") String name) {
        if (StringUtils.isBlank(name)) {
            throw new RuntimeException("error");
        }
        return "OK";
    }

    @ApiOperation("网关测试限流接口")
    @GetMapping("/yes")
    public String yes() {
        return "YES";
    }

    @ApiOperation("网关熔断降级测试接口")
    @GetMapping("/no")
    public String no() {
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            log.info("异常辣:{}",e);
        }
        return "BNO";
    }

}
